package com.teemor.tim.command.handler.state;

import com.alibaba.fastjson.JSON;
import com.teemor.tim.command.model.state.StateCommand;
import com.teemor.tim.enums.UserType;
import com.teemor.tim.model.user.UserStateModel;
import com.teemor.tim.bean.result.callback.CallBackResult;
import com.teemor.tim.command.annation.CommandMapping;
import com.teemor.tim.processor.state.DefaultUserStateProcessor;
import lombok.extern.slf4j.Slf4j;

/**
 * @ename zhoulk
 * @cname 周李科
 * @date 2020/12/14 10:20
 */
@CommandMapping("State")
@Slf4j
public class StateCommandHandler {


    @CommandMapping("StateChange")
    public CallBackResult callbackBeforeSendMsg(StateCommand command) {
        log.info("Call C2C.CallbackBeforeSendMsg: {}", JSON.toJSON(command));
        UserStateModel userStateModel = new UserStateModel(command.getInfo().getToAccount(), command.getInfo().getAction());
        String userId = userStateModel.getUserId();

        if (userId.equals("user0") || userId.equals("user1") || userId.equals("user2")) {
            userStateModel.setUserType(UserType.CUSTOMER_SERVICE.name());
        } else {
            userStateModel.setUserType(UserType.USER.name());
        }
        DefaultUserStateProcessor.processUserState(userStateModel);
        return new CallBackResult();
    }
}
